<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>请假审批</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
</head>

<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>请假审批</legend>
        </fieldset>
        <br>
        <table id="user-table" lay-filter="user-table"></table>
    </div>
</div>

<script type="text/html" id="user-toolbar">
    <button class="layui-btn layui-btn-sm" lay-event="search">
        <i class="layui-icon layui-icon-search"></i>
        学生速查
    </button>
</script>

<script type="text/html" id="user-bar">
    <button class="layui-btn layui-btn-sm" lay-event="add">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
</script>

<script src="../../../static/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'jquery'], function () {
        let table = layui.table;
        let $ = layui.jquery;
        let MODULE_PATH = "operate/";

        let cols = [
            [{
                type: 'numbers'
            },
                {
                    title: '学号',
                    field: 'userId',
                    align: 'center'
                },
                {
                    title: '姓名',
                    field: 'realName',
                    align: 'center'
                },
                {
                    title: '班级',
                    field: 'classes',
                    align: 'center'
                },
                {
                    title: '请假开始时间',
                    field: 'startTime',
                    align: 'center'
                },
                {
                    title: '请假结束时间',
                    field: 'endTime',
                    align: 'center'
                },
                {
                    title: '请假原因',
                    field: 'leaveReason',
                    align: 'center'
                },
                {
                    title: '状态',
                    field: 'status',
                    align: 'center',
                    templet: function (d) {
                        // console.log(d);
                        if (d.status === 1) {
                            return '<span class="layui-badge layui-bg-gray">等待审批</span>'
                        } else if (d.status === 0) {
                            return '<span class="layui-badge">拒绝通过</span>'
                        } else {
                            return '<span class="layui-badge layui-bg-green">审核通过</span>'
                        }
                    }
                },
                {
                    title: '辅导员ID',
                    field: 'counselorId',
                    align: 'center',
                    hide: true
                },
                {
                    title: '审核操作',
                    toolbar: '#user-bar',
                    align: 'center',
                    width: 130
                }
            ]
        ]


        let tableIns = table.render({
            elem: '#user-table',
            url: '/StudentLeave/getLeaveInfo',
            method: "post",
            page: {
                layout: ['count', 'prev', 'page', 'next', 'skip']
                , curr: 1
                , groups: 3
                , last: false
            },
            limit: 5,
            //limits:[5,10,20],
            cols: cols,
            id: 'user-table',
            skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新列表',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }],
            //一定要加这个参数代码，否则会由于layui自身的bug导致无法分页
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                let result;
                // console.log(res.data[0].birthday);
                // res.data[0].birthday = dateFormat(res.data[0].birthday, 'Y-M-D')
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            }
        });

        table.on('tool(user-table)', function (obj) {
            if (obj.event === 'add') {
                window.add(obj);
            } else if (obj.event === 'search') {
                window.search(obj);
            }
        });


        table.on('toolbar(user-table)', function (obj) {
            if (obj.event === 'add') {
                window.add(obj);
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'search') {
                //obj.del();
                window.search(obj);
            }
        });

        window.search = function (obj) {
            layer.open({
                type: 2,
                title: '学生快速查询',
                shade: 0.1,
                shadeClose: true,
                area: ['70%', '80%'],
                content: MODULE_PATH + 'leaveStuSearch.html'

            });
        };

        window.add = function (obj) {
            layer.open({
                type: 2,
                title: '审批请假信息',
                shade: 0.1,
                shadeClose: true,
                area: ['50%', '90%'],
                content: MODULE_PATH + 'editLeave.html',
                success: function (layero, index) {
                    let body = layer.getChildFrame('body', index);
                    //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    //console.log(obj.data);
                    let iframeWin = window[layero.find('iframe')[0]['name']];
                    body.find('#userId').html(obj.data['userId']);
                    body.find('#realName').html(obj.data['realName']);
                    body.find('#startTime').html(obj.data['startTime']);
                    body.find('#leaveId').val(obj.data['leaveId']);
                    body.find('#endTime').html(obj.data['endTime']);
                    body.find('#leaveReason').html(obj.data['leaveReason']);

                }
            });
        }

        window.refresh = function (param) {
            table.reload('user-table', {
                url: "/StudentLeave/getLeaveInfo",
                method: "post"
            });
        }
    })
</script>
</body>

</html>